<?php
/**
 * Created by PhpStorm.
 * User: jwb
 * Date: 2021/4/1
 * Time: 14:24
 */

namespace App\Extensions\Tools;

use Illuminate\Database\Eloquent\Collection;

class PatentKeepBatch extends BatchAction
{
    protected $selector = '.keep-posts';

    public function handle(Collection $collection)
    {
        $state = request()->get('keep_status')?1:0;
        foreach ($collection as $model) {
            if($model->keep_status != $state){
                $model->keep_status = $state;
                $model->save();
            }

        }
        return $this->response()->swal()->success('操作成功!')->refresh();
    }

    public function form()
    {
        $this->radio('keep_status', '维持状态')->options(['放弃维持', '继续维持'])->default(1);
    }

    public function html()
    {
        return "<a class='keep-posts btn btn-sm btn-primary'><i class='fa fa-hand-pointer-o'></i>标记维持</a>";
    }
}